package com.maple.controller.admin;


import com.maple.dto.OrdersCancelDTO;
import com.maple.dto.OrdersConfirmDTO;
import com.maple.dto.OrdersPageQueryDTO;
import com.maple.dto.OrdersRejectionDTO;
import com.maple.result.PageResult;
import com.maple.result.Result;
import com.maple.service.OrderService;
import com.maple.vo.OrderStatisticsVO;
import com.maple.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    OrderService orderService;

    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜索：{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }


    @GetMapping("/statistics")
    public Result queryStatistics(){
        log.info("各个状态的订单数量统计");
        OrderStatisticsVO orderStatisticsVO = orderService.queryStatistics();
        return Result.success(orderStatisticsVO);
    }


    @GetMapping("/details/{id}")
    public Result queryDetails(@PathVariable String id){
        log.info("查询订单详情:{}", id);
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }

    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单：{}", ordersConfirmDTO);
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }


    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单：{}", ordersRejectionDTO);
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }


    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("用户取消订单：{}", ordersCancelDTO);
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }


    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable String id){
        log.info("派送订单：{}", id);
        orderService.delivery(id);
        return Result.success();
    }


    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable String id){
        log.info("完成订单：{}", id);
        orderService.complete(id);
        return Result.success();
    }





}
